<template>
  <div class="fixed size-full p-0 m-0 inset-0">
    <router-view v-slot="{Component}">
      <component ref="child" :is="Component"></component>
    </router-view> <!-- 这里将渲染当前路由对应的组件 -->
  </div>
</template>

<script setup lang="ts">
import { SgesCalA as Sges1, utils, YkImageDisplay as Canvas, YkVideo as Video } from 'yklib'
import { ref } from 'vue'
import { menuOptionsType } from 'yklib/dist/packages/components/YkMenu/YkMenu.vue'
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Login from '..//components/useLogin.vue'
import Sges3 from '../components/ges/SgesCalC/SgesC.vue'
import AboutView from '@/views/AboutView.vue'
import DebugView from '@/views/DebugView.vue'
import PriceInfo from '@/components/PriceInfo.vue'

let child = ref()

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Login',
    component: Login
  },
  {
    path: '/SgesCalA',
    name: 'SgesCalA',
    component: Sges1
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes: routes
})

const template: menuOptionsType[] = [
    {
      label: '文件',
      submenu: [
        {
          label: '打开...',
          key: '打开',
          click: () => {
            utils.importData((str: string) => {
              let proj = JSON.parse(str)
              let currentPage = proj['currentPage'] || 'SgesCalA'
              localStorage.setItem('storeSgesCalA', proj.storeSgesCalA) // 将数据恢复到localStorage
              localStorage.setItem('storeSgesCalC', proj.storeSgesCalC) // 将数据恢复到localStorage
              router.push(currentPage) // 跳转到对应页面
              localStorage.setItem('currentPage', currentPage)
              location.reload()  // 刷新页面，加载localStorage中的数据
            })
          }   // 点击事件，需要传入函数对象，electron可以在此处指定点击事件
        },
        {
          type: 'separator'
        },
        {
          label: '保存到本地...',
          key: '保存到本地',
          click: () => {
            if (child.value.persistData) {
              child.value.persistData()
              let _1 = { 'storeSgesCalC': localStorage.getItem('storeSgesCalC') }
              _1['storeSgesCalA'] = localStorage.getItem('storeSgesCalA')
              _1['currentPage'] = localStorage.getItem('currentPage')
              let json_str = JSON.stringify(_1)
              utils.save_file(json_str)
            }
          }
        },
        {
          label: '关于',
          key: '关于',
          click: () => {
            localStorage.setItem('currentPage', 'about')
            router.push('about')
          }
        },
        {
          label: '退出',
          role: 'quit'
        }
      ]
    },
    {
      label: '工具',
      submenu:
        [
          {
            label: '塔式重力储能设计(方案1)',
            key: 'SgesCalA',
            click: () => {
              localStorage.setItem('currentPage', 'SgesCalA') // currentPage必须和key相同，根据该值跳转页面
              router.push('/SgesCalA')
            } // 鼠标点击事件
          },
          {
            label: '塔式重力储能设计(方案3)',
            key: 'SgesCalC',
            click: () => {
              localStorage.setItem('currentPage', 'SgesCalC')
              router.push('SgesCalC')
            }
          },
          {
            label: 'Canvas',
            key: 'Canvas',
            click: () => {
              localStorage.setItem('currentPage', 'Canvas')
              router.push('Canvas')
            }
          },
          // {
          //   label: 'Video',
          //   key: 'Video',
          //   click: () => {
          //     localStorage.setItem("currentPage", "Video")
          //     router.push('Video')
          //   }
          // },
          {
            type: 'separator'
          },
          {
            label: '储能系统成本计算',
            key: '储能系统成本计算',
            click: () => {
              localStorage.setItem('currentPage', 'Canvas')

            }
          },
          {
            label: '储能塔架设计',
            key: '储能塔架设计',
            click: () => {

            }
          },
          {
            label: '承托结构设计',
            key: '承托结构设计',
            click: () => {

            }
          },
          {
            label: '钢丝绳强度计算',
            key: '钢丝绳强度计算',
            click: () => {

            }
          },
          {
            label: '轴系强度计算',
            key: '轴系强度计算',
            click: () => {

            }
          },
          {
            label: '网盘（ipv4）',
            key: 'diskV4',
            click: () => {
              window.open('http://sges.yangke.site:20010', '_blank')
            }
          },
          {
            label: '网盘（ipv6）',
            key: 'diskV6',
            click: () => {
              window.open('http://disk.yangke.site:20010', '_blank')
            }
          }
        ]
    }
    ,
    {
      label: '查询',
      submenu:
        [
          {
            label: '全国各省峰谷电价信息',
            key: '全国各省峰谷电价信息',
            click: () => {
              localStorage.setItem('currentPage', 'pricePower')
              router.push('pricePower')
            }
          },
          {
            label: '储能系统成本计算',
            key: '储能系统成本计算',
            click: () => {
              router.push('debug')
            }
          },
          {
            label: '调试信息',
            key: 'debug',
            click: () => {
              localStorage.setItem('currentPage', 'debug')
              router.push('debug')
            }
          }

        ]
    }

  ]

</script>


<style scoped lang="postcss">
@tailwind base;
@tailwind components;
@tailwind utilities;
* {
  font-size: 16px;
}
</style>
